package com.ecfront.action;

import java.util.Date;
import java.util.Set;

import com.ecfront.dao.impl.UserDAOImpl;
import com.ecfront.exception.UserException;
import com.ecfront.pojo.Shop;
import com.ecfront.pojo.User;
import com.ecfront.pojo.UserGrade;
import com.ecfront.service.UserService;
import com.ecfront.service.impl.UserServiceImpl;
import com.ecfront.util.Constants;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class UserAction extends ActionSupport {
	protected User user;
	protected UserService userService;

	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	
	public void validate() {
		clearErrorsAndMessages();
		if (user.getName() == null || "".equals(user.getName())
				&& user.getEmail() == null || "".equals(user.getEmail())) {
			addFieldError("�û�������䲻��Ϊ��", user.getEmail());
		}
		if (user.getLoginPwd() == null || "".equals(user.getLoginPwd())) {
			addFieldError("��½���벻��Ϊ��", user.getLoginPwd());
		}
	}
	
	public String login() throws Exception {
		if (this.userService.findUserByNameOrEmailAndPassAndLock(
				user.getName(), user.getLoginPwd(), user.getIsLock())) {
			ActionContext.getContext().getSession().put(Constants.USERNAME_KEY,
					user.getName());
			return Action.SUCCESS;
		} else {
			super.addActionError("�û�������������벻ƥ�䣡");
			return Action.INPUT;
		}
	}
	@Override
	public String execute() throws Exception {
		return SUCCESS;
	}
}
